<?php
	require_once( 'core_DataBaseConnect.php' );
	require_once( 'core_ErrorCode.php' );
	require_once( 'core_Response.php' );
	require_once( 'dao_ModelDAO.php' );
	require_once( '_configs.php' );
	
	function func( $con, $post, $returnType )
	{
		// 1. 전체 모델 수
		$response = array();
		
		$searchType = $post[ 'type' ];
		
		$rankCode = NULL;
		$dutyCode = NULL;
		$partyCode = NULL;
		
		if( $searchType == 'rank' )
		{
			$rankCode = $post[ 'code' ];
		}else if( $searchType == 'duty' )
		{
			$dutyCode = $post[ 'code' ];
		}else if( $searchType == 'party' )
		{
			$partyCode = $post[ 'code' ];
		}
		
		$response[ 'count' ] = ModelDAO::countModels( $con, $rankCode, $dutyCode, $partyCode );
		
		// 2. 조회
		$result = ModelDAO::selectModels( $con, $post[ 'page' ], $post[ 'numPerPage' ], $rankCode, $dutyCode, $partyCode );
		$response[ 'model' ] = array();
		while( $fetch = DataBaseConnect::fetch_assoc( $result ) )
		{
			array_push( $response[ 'model' ], DataBaseConnect::fetchSerialize( $fetch, array( 'CODE', 'NAME', 'PICTURE', 'BIRTH_DATE', 'BIRTH_REGION', 'LAST_EDU', 'LAST_EDU_MEMO', 'SEX', 'MILITARY', 'MILITARY_MEMO', 'HEIGHT', 'REF', 'REF_LICENSE' ) ) );
		}
		
		return Response::SUCCESS( $response, $returnType );
	}
?>